import Vue from 'vue'
import Router from 'vue-router'

// 路由懒加载
const login = () => import('@/components/login/login.vue')
const accountLogin = () => import('@/routerPage/login/accountLogin.vue')
const register = () => import('@/components/register/register.vue')
const emailLogin = () => import('@/routerPage/login/emailLogin.vue')
const resetPassword = () => import('@/components/resetPassword/resetPassword.vue')

// user 首页
const homePageCom = () => import('@/routerPage/homePages/homePageCom.vue')
const homePage = () => import('@/components/home/homePage.vue')
const college = () => import('@/routerPage/homePages/college.vue')
const major = () => import('@/routerPage/homePages/major.vue')
const fillAspiration = () => import('@/routerPage/homePages/fillAspiration.vue')
const gaokaoNews = () => import("@/routerPage/homePages/news.vue")
const fillMajor = () => import("@/routerPage/homePages/fillMajor.vue")

// 学校概况 专业概况 后续需要修改路由
const collegeIntroduction = () => import("@/routerPage/homePages/collegeIntroduction.vue")
const introduction = () => import("@/routerPage/homePages/collegeIntroduction/introduction.vue")
const professional = () => import("@/routerPage/homePages/collegeIntroduction/professional.vue")
const provinceline = () => import("@/routerPage/homePages/collegeIntroduction/provinceline.vue")
//专业概况
const majorIntroduction = () => import("@/routerPage/homePages/majorIntroduction.vue")
const major_introduction = () => import("@/routerPage/homePages/majorIntroduction/introduction.vue")
const majorEmployment = () => import("@/routerPage/homePages/majorIntroduction/employment.vue")
const openInstitutions = () => import('@/routerPage/homePages/majorIntroduction/openInstitutions.vue')

// user 管理
const home = () => import('@/components/home/home.vue')
const info = () => import('@/routerPage/user/info.vue')
const changePassword = () => import('@/routerPage/user/changePassword.vue')
const voluntaryForm = () => import('@/routerPage/user/voluntaryForm.vue')
const collegeCollection = () =>import('@/routerPage/user/collegeCollection.vue')

// 后台管理
const managerHome = () => import('@/components/home/managerHome.vue')
const welcome = () => import("@/routerPage/manager/welcome/welcome.vue")
const users = () => import("@/routerPage/manager/user/users.vue")
const managers = () => import("@/routerPage/manager/user/managers.vue")
const rights = () => import("@/routerPage/manager/power/rights.vue")
const roles = () => import("@/routerPage/manager/power/roles.vue")
const news = () => import("@/routerPage/manager/news/news.vue")
const hotMajor = () => import("@/routerPage/manager/major/hotMajor.vue")
const searchMajor = () => import("@/routerPage/manager/major/searchMajor.vue")
const majorInfo = () => import("@/routerPage/manager/major/majorInfo.vue")
const admissionCollege = () => import("@/routerPage/manager/major/admissionCollege.vue")
const hotCollege = () => import("@/routerPage/manager/college/hotCollege.vue")
const searchCollege = () => import("@/routerPage/manager/college/searchCollege.vue")
const collegeInfo = () => import("@/routerPage/manager/college/collegeInfo.vue")
const fractionalLine = () => import("@/routerPage/manager/college/fractionalLine.vue")
const admissionPlan = ()=>import("@/routerPage/manager/college/admissionPlan.vue")
const majorLine =()=> import("@/routerPage/manager/college/majorLine.vue")
const exceptionLog = () => import("@/routerPage/manager/journal/exceptionLog.vue")
const operationLog = () => import("@/routerPage/manager/journal/operationLog.vue")

Vue.use(Router)

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const originalReplace = Router.prototype.replace
 
Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err)
}

export default new Router({
  // 先把页面的状态保存到一个对象中，当页面的url变化时找到对应的对象
  // 从而还原页面
  mode:"hash",
  routes: [
    {
      path: '/',
      component: homePage,
      redirect:"/homePage",
      children:[
        {
          path:"homePage",
          component:homePageCom,
        },
        {
          path:"college",
          component:college,
        },
        {
          path:"major",
          component:major
        },
        {
          path:"fillAspiration",
          component:fillAspiration,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          name:"fillMajor",
          path:"/fillAspiration/fillMajor",
          component:fillMajor,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"news",
          component:gaokaoNews
        },
      ]
    },
    {
      name:"college",
      path:"/college/:id",
      component:collegeIntroduction,
      redirect:"/college/:id/introduction",
      children:[
        {
          name:"introduction",
          path:"introduction",
          component:introduction,
        },
        {
          name:"professional",
          path:"professional",
          component:professional,
        },
        {
          name:"provinceline",
          path:"provinceline",
          component:provinceline,
        },
      ]
    },
    {
      name:"major",
      path:"/major/:id",
      component:majorIntroduction,
      redirect:"/major/:id/introduction",
      children:[
        {
          name:"introduction",
          path:"introduction",
          component:major_introduction,
        },
        {
          name:"employment",
          path:"employment",
          component:majorEmployment,
        },
        {
          name:"openInstitutions",
          path:"openInstitutions",
          component:openInstitutions,
        }
      ]
    },
    
    {
      path: '/login',
      component: login,
      redirect:'/login/accountLogin',
      children:[
        {
          path:"accountLogin",
          component:accountLogin,
        },
        {
          path: 'emailLogin',
          component: emailLogin,
        },
      ]
    },
   

    {
      path: '/register',
      component: register
    },
    {
      path: '/resetPassword',
      component:resetPassword
    },

    // user
    {
      path:"/home",
      component:home,
      meta: {
        requireAuth: true,  // 该路由项需要权限校验
      },
      redirect:"/home/info",
      children:[
        {
          path:"info",
          component:info,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"changePassword",
          component:changePassword,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"voluntaryForm",
          component:voluntaryForm,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"collegeCollection",
          component:collegeCollection,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
      ]
    },
    
    // manage
    {
      path:"/manager",
      component:managerHome,
      redirect:"/manager/welcome",
      meta: {
        requireAuth: true,  // 该路由项需要权限校验
      },
      children:[
        {
          path:"welcome",
          component:welcome,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"user",
          component:users,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"manage",
          component:managers,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"rights",
          component:rights,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"roles",
          component:roles,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"news",
          component:news,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"hotMajor",
          component:hotMajor,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"searchMajor",
          component:searchMajor,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"majorInfo",
          component:majorInfo,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"admissionCollege",
          component:admissionCollege,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"hotCollege",
          component:hotCollege,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"searchCollege",
          component:searchCollege,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"collegeInfo",
          component:collegeInfo,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"fractionalLine",
          component:fractionalLine,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"admissionPlan",
          component:admissionPlan,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"majorLine",
          component:majorLine,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"exceptionLog",
          component:exceptionLog,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        },
        {
          path:"operationLog",
          component:operationLog,
          meta: {
            requireAuth: true,  // 该路由项需要权限校验
          },
        }
      ]
    },

  ]
})




